#pragma once

#pragma warning(push)
#pragma warning(disable:4100)
#include "FFEX/ThostFtdcMblMdApi.h"
#pragma warning(pop)


class FastBlockQueue;

class FFEXMblHandler : public CThostFtdcMblMdSpi
{
public:
	FFEXMblHandler(FastBlockQueue& queue,ContractCodes const& contractCodes);
	virtual void OnFrontConnected();

	virtual void OnFrontDisconnected(int nReason)
	{
		UNREFERENCED_PARAMETER(nReason);
	}

	virtual void OnHeartBeatWarning(int nTimeLapse)
	{
		UNREFERENCED_PARAMETER(nTimeLapse);
	}

	virtual void OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	void Subscribe(char const* code);
// 	virtual void OnRspQryInstrument(CThostFtdcInstrumentField *pInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) 
// 	{
// 	}
//
// 	virtual void OnRspQryInstrumentStatus(CThostFtdcInstrumentStatusField *pInstrumentStatus, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) 
// 	{
// 	}
// 
// 	virtual void OnRspQryExchangeSequence(CThostFtdcExchangeSequenceField *pExchangeSequence, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) 
// 	{
// 	}

	virtual void OnRspError(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

	virtual void OnRspSubMBLMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);

// 	virtual void OnRspUnSubMBLMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) 
// 	{
// 	}

	virtual void OnRtnInstrumentStatus(CThostFtdcInstrumentStatusField *pInstrumentStatus);

	virtual void OnRtnMBLMarketData(CThostFtdcBaseMBLMarketDataField *pBaseMBLMarketData);

// 	virtual void OnRspQryMBLMarketData(CThostFtdcBaseMBLMarketDataField *pBaseMBLMarketData, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast) 
// 	{
// 	}
	void SetMblApi(CThostFtdcMblMdApi* val) { m_pMblApi = val; }
private:
	int GetContractIndex( char const* instrumentID);

	FastBlockQueue& m_queue;
	CThostFtdcMblMdApi* m_pMblApi;
	std::vector<std::string> m_codes;
	ContractCodes const& m_contractCodes;
	std::map<std::string,int> m_contractIndexMap;
};
